import "reflect-metadata"
import "../common";

events.removeAllListeners()
events.setMaxListeners(1000)

import { container as injector } from 'tsyringe'
/**
 * 制作一个APP管理框架
 */
import { Timer } from "../autox/timer";
import { APPS } from "./app";
import { KwaiApp } from "./KwaiApp";
import { HomeApp } from "./HomeApp";
import { MiuiAodApp } from "./MiuiAodApp";
import { SystemuiApp } from "./SystemuiApp";
import { RandomFindRedPacketTask } from "./RandomFindRedPacketTask";
import { TASKS } from "./task";
import { FollowFindRedPacketTask } from "./FollowFindRedPacketTask";
import { TakeRedPacketTask } from "./TakeRedPacketTask";
import { Context } from "./ctx";
import { Robot } from "./robot";

declare const runtime: any;
export const start = () => {

    const timer = injector.resolve(Timer)

    timer.setInterval(() => { }, 1000)
    events.on(`exit`, () => {
        console.hide()
        injector.dispose()
        events.removeAllListeners()
    })

    injector.register(APPS, {
        useValue: new KwaiApp()
    })
    injector.register(APPS, {
        useValue: new HomeApp()
    })
    injector.register(APPS, {
        useValue: new MiuiAodApp()
    })
    injector.register(APPS, {
        useValue: new SystemuiApp()
    })
    injector.register(TASKS, {
        useValue: new RandomFindRedPacketTask()
    })
    injector.register(TASKS, {
        useValue: new FollowFindRedPacketTask()
    })
    injector.register(TASKS, {
        useValue: new TakeRedPacketTask()
    })

    injector.register(Context, { useValue: new Context() })
    injector.register(Robot, { useValue: new Robot() })

    runtime.info.useShell = true;
    const robot = injector.resolve(Robot)
    robot.start()
}
